package com.caine.algorithm;

import java.util.Arrays;

public class PopSortAlgorithm {
    public static void main(String[] args) {
        int arr[] = new int[]{9,3,7,0,4,5,1,6};
        popSort(arr);
        printf(arr);
    }

    // 冒泡排序
    public static void popSort(int[] arr) {
        for (int i = arr.length - 1; i > 1; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    swap(arr, j, j + 1);
                }
            }
        }
    }

    public static void swap(int[] arr, int one, int two) {
        int tmp = arr[one];
        arr[one] = arr[two];
        arr[two] = tmp;
    }

    public static void printf(int[] arr){
        System.out.println("");
        Arrays.stream(arr).forEach(s-> System.out.print(s+" "));
        System.out.println("");
    }
}
